Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
¿Cómo puedo corregir este error de mecanografiado "La propiedad XXX no existe..."

He intentado diferentes formas de solucionar este problema, pero no puedo hacerlo con éxito.

Tengo el siguiente componente Reactjs:

 import EventItem from "../EventItem"; type Props = { events: [id: number, attributes: { slug: string; name: string; }]; }; const EventList = ({ events }: Props) => { return ( <section> <div className="max-w-7xl mx-auto px-4 mb-5"> <div className="max-w-sm mx-auto md:max-w-none bg-events-list p-4" data-aos="fade-up"> <div className="grid gap-12 md:grid-cols-4 md:gap-x-4 md:gap-y-8 items-start"> {events?.map((eventMap, index) => ( <EventItem key={index} url={`/e/${eventMap.attributes.slug}`} name={eventMap.attributes.name} /> ))} </div> </div> </div> </section> ); }; export default EventList;

Mecanografiado advierte que

 Property 'attributes' does not exist on type 'number | { slug: string; name: string; }'. Property 'attributes' does not exist on type 'number'.

Y mi estructura de datos es:

 { "id": 2, "attributes": { "name": "Event Name", "slug": "event-name", } }

¿Cómo puedo arreglarlo? ¿Qué pasa con mis accesorios de tipo? ¡Gracias!

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

type Props = { events: [id: number, attributes: { slug: string; name: string; }]; };

Su escritura dijo que los eventos son iguales a una matriz con una identificación y un objeto que contiene { slug: string; name: string; }

Pero para lograr lo que quieres debes escribir así

 type Props = { events: Array<{id: number, attributes: { slug: string; name: string; }}>; };

Ahora, events es una matriz de objetos con su estructura :)

about 4 years ago · Juan Pablo Isaza Report

0

Prueba lo siguiente:

 type Props = { events: { id: number, attributes: { slug: string; name: string; } } []; };
about 4 years ago · Juan Pablo Isaza Report

0

type Props = { events: [id: number, attributes: { slug: string; name: string; }]; };

Parece que el tipo de eventos debería ser objeto pero matriz. ¿Podrías probar esto?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!